import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { MdlSnackbarService, MdlDialogService } from '@angular-mdl/core';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/api';
import { ReportConfigService } from '../report-config.service'
import { SelectItem } from 'primeng/api';

@Component({
    templateUrl: './report-config-fieldadd.component.html',
    styleUrls: ['./report-config-fieldadd.component.scss'],
    providers: []
})
export class ReportConfigFieldAddComponent implements OnInit {
    fields: any[] = [];
    reportId: number;
    checkedIds: number[];
    selectedFields: any[] = [];
    cols: any[] = [
        { header: '字段名称', field: 'fieldName', style: { 'text-align': 'center', 'overflow': 'hidden' } },
        { header: '显示名称', field: 'fieldDisplayName', style: { 'text-align': 'center', 'overflow': 'hidden' } },
        { header: '数据类型', field: 'dataTypeName', style: { 'text-align': 'center', 'overflow': 'hidden' } }
    ];
    constructor(
        public ref: DynamicDialogRef,
        private config: DynamicDialogConfig,
        private reportConfigService: ReportConfigService) {
        this.reportId = config.data.reportId;
        this.checkedIds = config.data.checkedIds;
    }
    ngOnInit() {
        this.reportConfigService.loadReportFields(this.reportId).subscribe(data => {
            let temp = [];
            data.forEach(e => {
                if ($.inArray(e.fieldId, this.checkedIds) == -1) {
                    temp.push(e);
                }
            });
            this.fields = temp;
        });
    }

    /** 保存查询条件 */
    save() {
        this.ref.close(this.selectedFields);
    }


    /**取消关闭窗口 */
    cancel() {
        this.ref.close();
    }
}
